from datetime import datetime
from datetime import date
from datetime import timedelta

########################################################################
class eDateTime:
    """Basic time and date operations and comparators"""
    
    #----------------------------------------------------------------------
    def now(self):
        """Returns current datetime in ebackuper string format"""    
        return datetime.now().strftime("%Y-%m-%d-%H:%M:%S")

    #----------------------------------------------------------------------
    def diff(self, moment):
        """Calculates the difference between ebackuper string datetime
        and current time in seconds"""
        nowDateTime = datetime.now()
        preDate = moment.split('-')
        time = preDate[3].split(':')
        
        thenDateTime = datetime(int(preDate[0]), int(preDate[1]), int(preDate[2]),
                            int(time[0]), int(time[1]), int(time[2]))
        
        d = nowDateTime - thenDateTime
        return d.days * 24 * 60 * 60 + d.seconds
        
    #----------------------------------------------------------------------
    def isOlderThanXSeconds(self, moment, xSeconds):
        """True if moment was before xSeconds or more, false otherwise"""
        return self.diff(moment) > xSeconds
    
    #----------------------------------------------------------------------
    def isOlderThanXMinutes(self, moment, xMinutes):
        """True if moment was before xMinutes or more, false otherwise"""
        return self.diff(moment) / 60 > xMinutes